<template>
	<view class="contaner">
		<view class="header">
			<view class="header_left" @click="to(pro)">
				<image class="avatar" :src="pro.avater" mode="aspectFill"></image>
				{{pro.nickname}}
			</view>
			<view class="header_right">
				{{pro.create_at}}
			</view>
		</view>
		<view class="" @click="to(pro)">
			<view class="flex jsb">
				<view class="type" v-if="pro.type==1">
					#招商引资项目#
				</view>
				<view class="type" v-if="pro.type==2">
					#地方特产#
				</view>
				<view class="title">
					{{pro.title}}
				</view>
			</view>
			<view class="info">
				{{pro.content}}
			</view>
		</view>

		<view class="pic">
			<u-album :urls="imgs" multipleSize='221rpx' space='13rpx'></u-album>
		</view>
		<view class="line">

		</view>
		<view class="pinglun">
			<view class="flex" style="color: #333;font-size: 30rpx;">
				<view class="plline">

				</view>
				全部评论 <text style="font-size: 24rpx;">({{total}})</text>
			</view>

			<view class="pinglbox">
				<view class="pinlitem" v-for="(item,index) in pingllist" :key="index">
					<!-- 评论人 -->
					<view class="pinglzt">
						<view class="pinglr">
							<view class="flex">
								<image class="pinglav" :src="item.avater" mode="aspectFill"></image>
								{{item.nickname}}
							</view>
							<view class="pingltime">
								{{item.created_at}}
							</view>

						</view>
						<view class="pinglcon">
							{{item.comment}}
						</view>
					</view>

					<!-- 回复 -->
					<view class="huifubox" v-if="item.next.length>0">
						<view class="" v-for="(huif,i) in item.next" :key="i" style="margin-bottom: 20rpx;">
							
							<text style="color: #444CEF;margin-right: 10rpx;">{{huif.first}}</text> 回复 <text
								style="color: #444CEF;margin-left: 10rpx;">{{item.nickname}}</text>：{{huif.comment}}
						</view>
					</view>
					
				</view>
				<u-loadmore :status="status" @loadmore="onre"/>
			</view>
			
		</view>

		<view class="footer" :style="{bottom:height+'px'}">
			<u--textarea :adjustPosition='false' :showConfirmBar='false' v-model="value1" placeholder="发布评论.."
				border='none' autoHeight fixed></u--textarea>
			<view class="sendbox" @click="send">
				发送
			</view>
		</view>
	</view>
</template>

<script>
	import {dymicinfo,comment,makeComment} from '@/api/dymic.js'
	export default {
		data() {
			return {
				value1: '',
				height: 0,
				pro: {},
				pingllist: [],
				id:'',
				imgs:[],
				total:0,
				status: 'loadmore',
				page: 1,
				last_page:0
			};
		},
		onLoad(option) {
			let _this = this
			uni.onKeyboardHeightChange(res => {
				// console.log(res.height)
				_this.height = res.height
			})
			this.id=option.id
			this.getdymicinfo()
			this.getcomment()
		},
		methods:{
			getdymicinfo(){
				dymicinfo({dymic_id:this.id}).then(res=>{
					this.pro=res.data.data
					this.pro.image.split(',').map(t=>{
						this.imgs.push(this.$BASE_URL+t)
					})
				})
			},
			getcomment(){
				comment({dymic_id:this.id,page:this.page}).then(res=>{
					this.total=res.data.data.total
					this.status='loadmore'
					this.last_page=res.data.data.last_page
					uni.stopPullDownRefresh()
					this.pingllist=[...this.pingllist,...res.data.data.data]
				})
			},
			send(){
				if(!this.value1){
					uni.showToast({
						title:'请输入评论内容',
						icon:'none'
					})
					return
				}
				makeComment({dymic_id:this.id,comment:this.value1}).then(res=>{
					if(res.data.code==1){
						uni.showToast({
							title:'评论成功',
							icon:'none'
						})
						this.pingllist=[]
						this.getcomment()
						this.value1=''
					}
				})
			},
			onre(){
				this.page++
				if(this.page<=this.last_page){
					this.getcomment()
				}else{
					this.status='nomore'
				}
			}
		},
		onReachBottom() {
			this.onre()
		},
		onPullDownRefresh() {
			this.page=1
			this.pingllist=[]
			this.imgs=[]
			this.getdymicinfo()
			this.getcomment()
		}
	}
</script>

<style lang="less">
	.contaner {
		padding: 23rpx 30rpx 140rpx;

		.header {
			padding: 0 1rpx 0 6rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 25rpx;

			.header_left {
				display: flex;
				align-items: center;
				color: #333333;
				font-size: 30rpx;

				.avatar {
					width: 56rpx;
					height: 56rpx;
					border-radius: 50%;
					margin-right: 14rpx;
				}
			}

			.header_right {
				font-size: 26rpx;
				color: #949492;
			}

		}

		.type {
			font-size: 32rpx;
			color: #FF7D12;
			line-height: 64rpx;
			background: rgba(255, 123, 38, 0.2);
			padding: 0 20rpx;
			border-radius: 10rpx;
			margin-left: 7rpx;
		}

		.title {
			color: #333;
			font-size: 32rpx;
		}

		.info {
			font-size: 30rpx;
			color: #333;
			padding-left: 10rpx;
			margin-top: 24rpx;
			margin-bottom: 20rpx;
			line-height: 45rpx;
		}

		.pic {
			margin-bottom: 55rpx;
		}

		.inputbox {
			flex: 1;
			margin-right: 19rpx;
			padding-left: 43rpx;
			line-height: 63rpx;
			color: #949492;
			font-size: 28rpx;
			background-color: #f9f9f9;
			border-radius: 32rpx;
		}

		.pinglun {

			.plline {
				width: 8rpx;
				height: 30rpx;
				background: #FE712A;
				border-radius: 4rpx;
				margin-right: 10rpx;
			}

			.pinglbox {
				padding: 14rpx 30rpx;

				.pinlitem {
					border-bottom: 3rpx solid #FBFBFB;
					padding: 24rpx 2rpx 28rpx;
					color: #333;
					font-size: 28rpx;

					.pinglzt {

						.pinglr {
							display: flex;
							align-items: center;
							justify-content: space-between;
							font-size: 30rpx;

							.pinglav {
								width: 56rpx;
								height: 56rpx;
								border-radius: 50%;
								margin-right: 13rpx;
							}

							.pingltime {
								color: #949492;
							}
						}

						.pinglcon {
							padding: 16rpx 0 21rpx 67rpx;
							line-height: 36rpx;
						}

					}

					.huifubox {
						padding: 32rpx 29rpx 14rpx 22rpx;
						width: 521rpx;
						margin-left: 65rpx;
						line-height: 36rpx;
						background: #F5F5F5;
						border-radius: 7px;
					}
				}
			}
		}

		.line {
			width: 690rpx;
			height: 3rpx;
			background: #fdfdfd;
			margin: 0 auto;
		}

		/deep/.u-album__row__wrapper {
			border-radius: 15rpx;
			overflow: hidden;
		}


		.flex {
			display: flex;
			align-items: center;
		}

		.jsb {
			justify-content: space-between;
		}

	}

	.footer {
		width: 690rpx;

		background: #FFFFFF;
		box-shadow: 0px 4rpx 38rpx 0px rgba(0, 0, 0, 0.06);
		position: fixed;
		bottom: 0;
		display: flex;
		align-items: center;
		justify-content: center;
		left: 0;
		padding: 40rpx 30rpx;

		.sendbox {
			margin-left: 20rpx;
			padding: 0 28rpx;
			line-height: 63rpx;
			background: linear-gradient(265deg, #FF8717, #FF5F00);
			border-radius: 32rpx;
			font-size: 28rpx;
			color: #fff;
		}
	}

	/deep/.u-textarea {
		background-color: #F9F9F9 !important;
		border-radius: 32rpx !important;
		padding: 18rpx 43rpx !important;
		padding-top: 18rpx !important;
		padding-bottom: 18rpx !important;
	}

	/deep/.uni-textarea-wrapper {
		line-height: 40rpx !important;
	}
</style>
